package b4.view
{
	import b4.ApplicationFacade;
	import b4.model.SmartBirdExtension;
	import b4.model.TownProxy;
	import b4.model.vo.player.Role;
	import b4.view.component.user.UserPane;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class UserPaneMediator extends Mediator implements IMediator
	{
		public static const NAME:String = 'UserPaneMediator';
		
		public function UserPaneMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}
		
		override public function listNotificationInterests():Array
		{
			return [
				ApplicationFacade.MAINROLE_LOADED
			];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			switch ( name )
			{
				case ApplicationFacade.MAINROLE_LOADED:
					var mainRole:Role = townProxy.vo.town.myRole;
					userPane.refreshInfo(mainRole);
					userPane.refreshAppearance(mainRole.appearance);
				break;
			}
		}
		
		override public function onRegister():void
		{
			sendNotification(ApplicationMediator.ADD_CHILD, viewComponent);
		}
		
		override public function onRemove():void
		{
		}
		
		private function get userPane():UserPane
		{
			return viewComponent as UserPane;
		}
		
		private function get townProxy():TownProxy
		{
			return facade.retrieveProxy( TownProxy.NAME ) as TownProxy;
		}
	}
}